'use strict';

const { Controller } = require('egg');


class GoodsTypeController extends Controller {

  async create() {
    const { ctx } = this;
    // const { created_use_uuid, name, intro, parent_type_uuid, deleted } = ctx.request.body;
    // const newOne = { created_use_uuid, name, intro, parent_type_uuid, deleted};
    // const goodsType = await ctx.model.GoodsTypes.saveNew(newOne)
    // ctx.helper.renderSuccess(ctx, { data: goodsType, message: 'ok'})
    const ctxData = ctx.request.body;
    try { 
      const addedOne = await ctx.service.goodsTypes.addOne(ctxData);
      ctx.helper.renderSuccess(ctx, { data: addedOne, message: 'ok'});
    } catch(err) {
      ctx.helper.renderFail(ctx, { data:  err.message, message: 'error'})
    }
    
    
  }

  async list () {
    const { ctx } = this;
    let { page, pageSize, ...filter } = ctx.request.query;
    const getListData = await ctx.service.goodsTypes.getlist({page, pageSize, filter})
    ctx.helper.renderSuccess(ctx, { data: getListData, message: 'ok'})
  }

  async findDetails () {
    const { ctx } = this;
    const { uuid } = ctx.request.params;
    const res = await ctx.model.GoodsTypes.findByPk(uuid);
     ctx.helper.renderSuccess(ctx, { data: res, message: 'ok'})
  }
}

module.exports = GoodsTypeController;